import Vue from 'vue'
import App from './App'
import router from './router'

import ViewUI from 'view-design';
import '@/assets/styles/index.less'

import VueI18n from 'vue-i18n'
import en from 'view-design/dist/locale/en-US'
import zh from 'view-design/dist/locale/zh-CN'

import XcStorage from './utils/storage'
import XcCollect from './utils/collect'
import XcUtil from './utils/util'
import XcHttp from "./config"

Vue.use(ViewUI)
Vue.use(VueI18n)

const messages = {
  en: Object.assign(require('./i18n/language-en').default, en),
  zh: Object.assign(require('./i18n/language-zh').default, zh)
}

// Create VueI18n instance with options
const i18n = new VueI18n({
  locale: 'zh',  // set locale
  messages  // set locale messages
})

Vue.config.productionTip = false

/* eslint-disable no-new */
let $vue = new Vue({
  i18n,
  router,
  components: { App },
  template: '<App/>'
})

// 自定义工具
Vue.prototype.$util = new XcUtil($vue)
Vue.prototype.$collect = new XcCollect()
Vue.prototype.$storage = new XcStorage($vue)
Vue.prototype.$md = new XcHttp($vue)

// 全局钩子，只有当路由变化时才会出现
router.beforeEach((to, from, next) => {
  if (to.path !== '/login' && !$vue.$storage.checkLogin()) next({ path: '/login' })
  next()
})

// 设置Message全局变量
Vue.prototype.$Message.config({
  duration: 3
})

$vue.$mount('#app')
